package com.world.rickcloudendpoint.service.runner;

import com.world.rickcloudendpoint.service.net.websocket.WebSocketServer;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @description: 所有线程服务在这里启动
 * @author: jlsong
 * @date: 2021/12/08 22:57:24
 * @version: 1.0
 */
@Component
@Order(3)
public class WebSocketServerRunner implements ApplicationRunner {

    /**
     *  网页web socket 服务
     */
    final
    WebSocketServer socketServer;

    public WebSocketServerRunner(WebSocketServer socketServer) {
        this.socketServer = socketServer;
    }

    ExecutorService pool = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue());


    @Override
    public void run(ApplicationArguments args) throws Exception {
        pool.execute(() -> socketServer.start());
    }
}
